<?php
namespace Admin\Controller;
class ComplainController extends AdminController{
	//抵押资料
    protected function _initialize() {
		parent::_initialize ();
	}
	//渠道投诉列表
	public function index(){
		$status=$_GET['status']!=''?$_GET['status']:'';
		$list=$this->get_complain($status,1);
		$this->assign('list',$list);
		$this->display();
	}

	//渠道投诉处理
	public function place(){
		if(IS_POST){
            $data=array(
              'status'=>1,
              'del_result'=>$_POST['del_result'],
              'update_time'=>time(),
            	);
            $result=M('complain')->where('id='.$_POST['id'])->save($data);
            if($result){
              $this->success('处理成功',U('Complain/index'));
            }else{
              $this->error('处理失败',U('Complain/index'),0);
            }
		}else{
			$complain=$this->getInfo('*','complain','id='.I('get.id',0,'intval'));
			$this->assign('complain',$complain);
			$this->display();
		}

	}

	//渠道投诉删除
	public function place_del(){
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'complain');
		if($result){
          $this->success('删除成功',U('Complain/index'));
		}else{
			$this->error('删除失败',U('Complain/index'));
		}
		//$this->returnResult($result);
    }

	public function add_info(){
		$this->display();
	}
//客户投诉录入
	public function User_add(){
		if(IS_POST){
		   $group=$this->getInfo('*','group','id='.$_POST['gid']);
           $data= array(
           	'group_id' =>$_POST['gid'] ,
           	'group_name'=>$group['name'],
           	'title' =>$_POST['title'] ,
           	'type' =>$_POST['complain_type'] ,
           	'user_name' =>$_POST['user_name'] ,
           	'user_phone' =>$_POST['user_phone'] ,
           	'desc' =>$_POST['desc'] ,
           	'add_time' =>time() ,
           	'business_type'=>1,
           	'update_time'=>time()
           	);
           $result=M('complain')->add($data);
           if($result){
             $this->success('录入成功',U('Complain/add_index'));
           }else{
           	 $this->error('录入失败',U('Complain/add_index'),0);
           }
		}else{
			$group=$this->getList('*','group','work_status=1 and pid=0 and status=1');
			$this->assign('group',$group);
			$this->display();
		}

	}

	//投诉列表
	public function add_index(){
		$status=$_GET['status']!='' ? $_GET['status'] : '';
		$list=$this->get_complain($status,1);
		$this->assign('list',$list);
		$this->display();
	}

	public function get_complain($status,$business_type){
        $where='1=1';
        $where .= I('get.user_name') != '' ? ' and user_name like "%'.I('get.user_name').'%"' : '';
        $where .= I('get.telephone') != '' ? ' and user_phone = '.I('get.telephone') : '';
        $where .= I('get.create_time_beg') != '' ? ' and add_time >= '.strtotime(I('get.create_time_beg')) : '';

        $where .= I('get.create_time_end') != '' ? ' and add_time < '.strtotime(I('get.create_time_end')) : '';
        if($status!=''){
           $where .= ' and status='.$status;
        }
        $where.=' and business_type='.$business_type;
        // if(session('adminInfo.gpid')!=0){
        //   $where.=' and group_id='.session('adminInfo.gpid');
        // }
       $list=$this->getList('*','complain',$where,'id desc',true);
       return $list;
	}

}